<%= javascript_include_tag 'jscalendar/calendar.js' , 'jscalendar/calendar-setup.js', 'jscalendar/lang/calendar-en.js' %>
<style type="text/css">@import url(/javascripts/jscalendar/calendar-win2k-1.css);</style>

<script>

function disp_del(id) {
   if(id=='-1') {notice('Error: can not delete this event'); return;}
   else notice('Event has been deleted');
   var el = document.getElementById('de'+id);
   new Effect.Fade(el);
   var el=document.getElementById('item_'+id);
   new Effect.BlindUp(el,{delay:1});
   }
function del(id) {
   if (confirm('Delete this event ?')) {
      var el = document.getElementById('de'+id);
      el.src = '/images/loading.gif';
      new Ajax.Request('/calendar/delete/'+id, {asynchronous:true, evalScripts:true, onComplete:function(request){disp_del(request.responseText)}});
      }
   return false;
   }
   
</script>

<% form_tag('/calendar/create') do -%>
<table>
<tr><td>Project</td><td><%= select('new', 'project_id', session['user'].projects.sort_by{|p| [p.name.upcase]}.map{|p| [p.name,p.id]}, {:include_blank => true},{:onchange=>"new Ajax.Updater('events', '/calendar/select_project/'+this.value, {asynchronous:true, evalScripts:true})"}) %>
Select a project to display tasks</td></tr>
<tr><td>Title</td><td><%= text_field('new', 'title') %></td></tr>
<tr><td>Date</td><td><%= text_field('new', 'date') %></td></tr>
<tr><td>&nbsp;</td><td><%= submit_tag('Add event',{:class => 'button'}) -%></td></tr>
</table><br/>
<% end -%>
<br/>
<div id="events"><%=render(:action=>'select_project')%></div>
	

<script>
Calendar.setup({
   inputField     :    "new_date",
   ifFormat       :    "%Y-%m-%d",
   showsTime      :    false
   });
</script>
